/**
 * @(#)com.framework.web.sys.service.UserService
 *
 * Copyright (c) 2014-2018 上海天跃科技有限公司
 *
 * DESC:
 *
 */
package com.framework.web.sys.service;

import com.framework.web.sys.domain.CodeItems;
import com.framework.web.sys.repository.CodeItemsRepository;
import com.framework.web.sys.repository.specifications.CodeItemsSpecs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author fusf
 * @version 1.0  2016/1/8
 */
@Service
public class CodeItemsService {

    @Autowired
    private CodeItemsRepository codeItemsRepository;

    /**
     * 新增或者保存
     * @param codeItems
     * @return
     */
    public CodeItems save(CodeItems codeItems) {
        return codeItemsRepository.save(codeItems);
    }

    /**
     * 删除
     * @param id
     */
    public void  delete(String id) {
        codeItemsRepository.delete(id);
    }
    /**
     * 根据id查询
     * @param id
     * @return
     */
    public CodeItems findById(String id) {
        return codeItemsRepository.findOne(id);
    }


    /**
     * 分页查找
     * @param codeItems
     * @param pr
     * @return
     */
    public Page<CodeItems> getPageList(CodeItems codeItems, PageRequest pr) {
        Page<CodeItems> totalList = codeItemsRepository.findAll(
                CodeItemsSpecs.LikeCodeItemsName(codeItems), pr);
        return totalList;
    }

    /**
     * 根据客户id和类别categoryCode查询列表
     * @param categoryCode
     * @return
     */
    @Cacheable(value="dictCache", key="#p0")
    public List<CodeItems> getListByCategoryCode(String categoryCode) {
        return codeItemsRepository.findByCategoryCode(categoryCode);
    }

    /**
     * 刷新缓存
     */
    @CacheEvict(value="dictCache", allEntries=true)
    public void refreshCache() {

    }

}
